﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Root="clr-namespace:Elysium.Theme">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/Elysium.Theme;component/Themes/SharedResources.xaml"/>
    </ResourceDictionary.MergedDictionaries>
    
    <Style x:Key="ScrollBarLineDownButtonStyle" TargetType="{x:Type RepeatButton}">
        
        <Setter Property="Background" Value="{StaticResource Transparent}"/>
        <Setter Property="BorderBrush" Value="{StaticResource ForegroundMiddlelight}"/>
        <Setter Property="BorderThickness" Value="{x:Static Root:Parameters.DefaultThickness}"/>
        
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Focusable" Value="False"/>

        <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="False"/>

        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding Background}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Polygon Points="0,0 3,4 6,0"
                                 Fill="{TemplateBinding BorderBrush}"
                                 StrokeThickness="0"
                                 Stretch="Uniform"
                                 Width="{TemplateBinding Root:Parameters.ScrollBarArrowSize}" Height="{TemplateBinding Root:Parameters.ScrollBarArrowSize}"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        
        <Style.Triggers>            
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="BorderBrush" Value="{StaticResource ForegroundLowlight}"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="BorderBrush" Value="{StaticResource Foreground}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="BorderBrush" Value="{StaticResource Disabled}"/>
            </Trigger>            
        </Style.Triggers>
        
    </Style>

    <Style x:Key="ScrollBarLineUpButtonStyle" TargetType="{x:Type RepeatButton}">
        <Setter Property="LayoutTransform">
            <Setter.Value>
                <RotateTransform Angle="180"/>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ScrollBarLineLeftButtonStyle" TargetType="{x:Type RepeatButton}">
        <Setter Property="LayoutTransform">
            <Setter.Value>
                <RotateTransform Angle="-90"/>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ScrollBarLineRightButtonStyle" TargetType="{x:Type RepeatButton}">
        <Setter Property="LayoutTransform">
            <Setter.Value>
                <RotateTransform Angle="90"/>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ScrollBarPageButtonStyle" TargetType="{x:Type RepeatButton}">

        <Setter Property="Background" Value="{StaticResource Transparent}"/>
        <Setter Property="BorderBrush" Value="{StaticResource Transparent}"/>
        <Setter Property="BorderThickness" Value="0"/>

        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Focusable" Value="False"/>

        <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="False"/>

        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Rectangle Fill="{TemplateBinding Background}"
                               Stroke="{TemplateBinding BorderBrush}"
                               StrokeThickness="0"
                               SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        
    </Style>

    <Style x:Key="ScrollBarThumbStyle" TargetType="{x:Type Thumb}">

        <Setter Property="Background" Value="{StaticResource ForegroundMiddlelight}"/>
        <Setter Property="BorderBrush" Value="{StaticResource Transparent}"/>
        <Setter Property="BorderThickness" Value="0"/>

        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Focusable" Value="False"/>

        <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="False"/>
        
        <Setter Property="Padding">
            <Setter.Value>
                <Thickness Left="{x:Static Root:Parameters.DefaultPaddingValue}"
                           Top="0"
                           Right="0"
                           Bottom="0"/>
            </Setter.Value>
        </Setter>

        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Grid Background="{StaticResource Transparent}"
                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Rectangle Fill="{TemplateBinding Background}"
                                   Stroke="{TemplateBinding BorderBrush}"
                                   StrokeThickness="0"
                                   Margin="{TemplateBinding Padding}"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{StaticResource ForegroundLowlight}"/>
            </Trigger>
            <Trigger Property="IsDragging" Value="True">
                <Setter Property="Background" Value="{StaticResource Foreground}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Background" Value="{StaticResource Disabled}"/>
            </Trigger>
        </Style.Triggers>

    </Style>
    
    <ControlTemplate x:Key="HorizontalScrollBarTemplate" TargetType="{x:Type ScrollBar}">
        <Border Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <Grid Background="{StaticResource Transparent}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <RepeatButton Grid.Column="0"
                              Command="{x:Static ScrollBar.LineLeftCommand}"
                              IsEnabled="{TemplateBinding IsEnabled}"
                              Root:Parameters.ScrollBarArrowSize="{TemplateBinding Root:Parameters.ScrollBarArrowSize}"
                              Style="{StaticResource ScrollBarLineLeftButtonStyle}"
                              Visibility="Collapsed"/>
                <Track x:Name="PART_Track"
                       Grid.Column="1">
                    <Track.DecreaseRepeatButton>
                        <RepeatButton Command="{x:Static ScrollBar.PageLeftCommand}"
                                      IsEnabled="{TemplateBinding IsEnabled}"
                                      Style="{StaticResource ScrollBarPageButtonStyle}"/>
                    </Track.DecreaseRepeatButton>
                    <Track.Thumb>
                        <Thumb IsEnabled="{TemplateBinding IsEnabled}"
                               Style="{StaticResource ScrollBarThumbStyle}"/>
                    </Track.Thumb>
                    <Track.IncreaseRepeatButton>
                        <RepeatButton Command="{x:Static ScrollBar.PageRightCommand}"
                                      IsEnabled="{TemplateBinding IsEnabled}"
                                      Style="{StaticResource ScrollBarPageButtonStyle}"/>
                    </Track.IncreaseRepeatButton>
                </Track>
                <RepeatButton Grid.Column="2"
                              Command="{x:Static ScrollBar.LineRightCommand}"
                              IsEnabled="{TemplateBinding IsEnabled}"
                              Root:Parameters.ScrollBarArrowSize="{TemplateBinding Root:Parameters.ScrollBarArrowSize}"
                              Style="{StaticResource ScrollBarLineRightButtonStyle}"
                              Visibility="Collapsed"/>
            </Grid>
        </Border>
    </ControlTemplate>

    <ControlTemplate x:Key="VerticalScrollBarTemplate" TargetType="{x:Type ScrollBar}">
        <Border Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <Grid Background="{StaticResource Transparent}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <RepeatButton Grid.Row="0"
                              Command="{x:Static ScrollBar.LineUpCommand}"
                              IsEnabled="{TemplateBinding IsEnabled}"
                              Root:Parameters.ScrollBarArrowSize="{TemplateBinding Root:Parameters.ScrollBarArrowSize}"
                              Style="{StaticResource ScrollBarLineUpButtonStyle}"
                              Visibility="Collapsed"/>
                <Track x:Name="PART_Track"
                       Grid.Row="1"
                       IsDirectionReversed="True">
                    <Track.DecreaseRepeatButton>
                        <RepeatButton Command="{x:Static ScrollBar.PageUpCommand}"
                                      IsEnabled="{TemplateBinding IsEnabled}"
                                      Style="{StaticResource ScrollBarPageButtonStyle}"/>
                    </Track.DecreaseRepeatButton>
                    <Track.Thumb>
                        <Thumb IsEnabled="{TemplateBinding IsEnabled}"
                               Style="{StaticResource ScrollBarThumbStyle}"/>
                    </Track.Thumb>
                    <Track.IncreaseRepeatButton>
                        <RepeatButton Command="{x:Static ScrollBar.PageDownCommand}"
                                      IsEnabled="{TemplateBinding IsEnabled}"
                                      Style="{StaticResource ScrollBarPageButtonStyle}"/>
                    </Track.IncreaseRepeatButton>
                </Track>
                <RepeatButton Grid.Row="2"
                              Command="{x:Static ScrollBar.LineDownCommand}"
                              IsEnabled="{TemplateBinding IsEnabled}"
                              Root:Parameters.ScrollBarArrowSize="{TemplateBinding Root:Parameters.ScrollBarArrowSize}"
                              Style="{StaticResource ScrollBarLineDownButtonStyle}"
                              Visibility="Collapsed"/>
            </Grid>
        </Border>
    </ControlTemplate>

    <Style TargetType="{x:Type ScrollBar}">

        <Setter Property="Background" Value="{StaticResource Transparent}"/>
        <Setter Property="BorderBrush" Value="{StaticResource ForegroundMiddlelight}"/>

        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Focusable" Value="False"/>
        
        <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="False"/>

        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        
        <Style.Triggers>

            <Trigger Property="Orientation" Value="Horizontal">
                
                <Setter Property="BorderThickness">
                    <Setter.Value>
                        <Thickness Left="0" Top="0" Right="0" Bottom="{x:Static Root:Parameters.DefaultStrokeThickness}"/>
                    </Setter.Value>
                </Setter>

                <Setter Property="MinHeight" Value="6"/>
                <Setter Property="Height" Value="6"/>
                <Setter Property="MaxHeight" Value="10"/>
                
                <Setter Property="Template" Value="{StaticResource HorizontalScrollBarTemplate}"/>
                
            </Trigger>

            <Trigger Property="Orientation" Value="Vertical">

                <Setter Property="BorderThickness">
                    <Setter.Value>
                        <Thickness Left="0" Top="0" Right="{x:Static Root:Parameters.DefaultStrokeThickness}" Bottom="0"/>
                    </Setter.Value>
                </Setter>

                <Setter Property="MinWidth" Value="6"/>
                <Setter Property="Width" Value="6"/>
                <Setter Property="MaxWidth" Value="10"/>

                <Setter Property="Template" Value="{StaticResource VerticalScrollBarTemplate}"/>

            </Trigger>

        </Style.Triggers>
        
    </Style>

</ResourceDictionary>